const sql = require("../../mysql");

module.exports = async ctx => {
  try {
    let user = await sql.User.findOne({
      attributes: ["uname", "createdAt", "updatedAt", "id", "role"],
      where: {
        id: ctx.request.userId
      }
    });

    ctx.body = {
      code: 0,
      data: user
    };
  } catch (error) {
    ctx.response.status = 200;

    ctx.body = {
      code: -1,
      msg: error.errors ? error : error.errors[0].message
    };
  }
};
